<%--
  Created by IntelliJ IDEA.
  User: zhidi
  Date: 2017-03-13
  Time: 22:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>试图解析器</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6QGeCqPWzjMvu8AlTeGfqERitdu5R7eB"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/layer.js"></script>
    <title>设置点的新图标</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
    jQuery(document).ready(function(){
        // 百度地图API功能
        var map = new BMap.Map("allmap");
        var point = new BMap.Point(121.10,31.45);
        map.centerAndZoom(point, 15);
        var mapType1 = new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]});
        var mapType2 = new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT});
        map.addControl(mapType1);          //2D图，卫星图
        map.addControl(mapType2);
        map.enableScrollWheelZoom(true);

        //创建小狐狸
        var pt = new BMap.Point(121.10,31.45);
        var myIcon = new BMap.Icon("${pageContext.request.contextPath}/static/img/car.png", new BMap.Size(150,78.5));
        var marker2 = new BMap.Marker(pt,{icon:myIcon});  // 创建标注
        map.addOverlay(marker2);// 将标注添加到地图中
        window.setInterval(aa,5000);
        function aa(){
            $.ajax({
                type: "get",
                url:"${pageContext.request.contextPath}/test/getPos.do", success: function(json){
                    map.clearOverlays();
                    for(var i=0;i<json.length;i++){
                        marker2 = new BMap.Marker(new BMap.Point( json[i].lng,json[i].lat),{icon:myIcon});  // 创建标注
                        //layer.msg(i+': '+json[i].lng+' '+json[i].lat);
                        map.addOverlay(marker2);
                        var label = new BMap.Label(json[i].busLineName+' '+json[i].carId+' '+json[i].stationName,{offset:new BMap.Size(0,-20)});
                        marker2.setLabel(label);
                    }

                },
                error: function(){
                    alert('fail');
                }
            });

        }

    });


</script>
